package com.app.teaware.bean;

import android.text.InputType;
import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;
import java.util.ArrayList;

import my.LogUtil;
import my.TimeUtils;

public class ParamsEditItemData implements  Serializable {

	//编辑类型 1 文本（不可编辑） 2文本可编辑 3选择  4标题类型  5 时间（目前仅有设备时间） 6开关  7选择并关联 8编辑并可选择  9单个action提交项
	public static final int EDIT_TYPE_TEXT = 1,EDIT_TYPE_EDIT = 2,EDIT_TYPE_CHOOSE= 3,EDIT_TYPE_TITLE = 4,EDIT_TYPE_TIME = 5,EDIT_TYPE_BOOLEAN = 6,EDIT_TYPE_CHOOSE_RELATE = 7,EDIT_TYPE_EDIT_AND_CHOOSE = 8,EDIT_TYPE_BUTTON = 9,EDIT_TYPE_DIIVIDER = 10,EDIT_TYPE_EDIT_BIG_NAME = 11,EDIT_TYPE_PROVINCE = 12;

	//编辑输入类型  无或0默认，普通文本 1普通字符串 2 数字 3浮点数（带小数点的数字）   4正负数  5 带特殊字符参数，ATshow返回和 action提交的时候都用双引号包裹，显示则无双引号
	public static final int INPUT_TYPE_DEFAULT = 1 , INPUT_TYPE_NUM = 2 ,INPUT_TYPE_FLOAT = 3 ,INPUT_TYPE_SIGNED = 4,INPUT_TYPE_TEXT_WITH_MASK = 5 ;

	public static final String TIME_FORMAT = "\"yyyy/MM/dd,HH:mm:ss\"";
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private String name;
	private String name_show;
	private int edit_type = EDIT_TYPE_TEXT;
	private int inputtype = INPUT_TYPE_DEFAULT ;
	private ArrayList<ParamsChooseItemData> choose_items;
	private String value;
	private String value_default;
	private String value_name;
	private String hint;
	private String name_des;
	private String unit;
    private String wrong_hint;
	private String relate_name;
	private String relate_name_value;
	private int max_value = -1;
	private int min_value = -1;

	private int text_color = -1;

	private int group_position = -1;

	private boolean isVisiable = true;

	private boolean[] listTimeBoolean;
	private String timeFormat;

	private ArrayList<String> urlList;

	private int max_length = -1;

	private boolean isAllowEmpty = true;

	public ParamsEditItemData() {
	}
	public ParamsEditItemData(String name, String value) {
		this.name = name;
		this.value = value;
	}

	public ParamsEditItemData(String name, ArrayList<String> urlList) {
		this.name = name;
		this.urlList = urlList;
	}

	public ParamsEditItemData(String name_show, String name,String value,int edit_type) {
		this.name_show = name_show;
		this.name = name;
		this.value = value;
		this.edit_type = edit_type;
	}

	public String getName() {
		if(TextUtils.isEmpty(name)){
			return  "";
		}
		return name;
	}
	@JSONField(serialize = false)
	public String getName_STR() {
		if(!TextUtils.isEmpty(name_show))return name_show;
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public String getName_show() {
		if(TextUtils.isEmpty(name_show)){
			return  "";
		}
		return name_show;
	}

	public void setName_show(String name_show) {
		this.name_show = name_show;
	}

	public int getEdit_type() {
		return edit_type;
	}

	public void setEdit_type(int edit_type) {
		this.edit_type = edit_type;
	}


	public String getValue() {
		if(TextUtils.isEmpty(value))return "";
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	@JSONField(serialize =  false)
	public void setDefaultIfValueEmpty(){
		if(TextUtils.isEmpty(value) && !TextUtils.isEmpty(value_default)){
			value = value_default;
		}
	}
	@JSONField(serialize =  false)
	public String getValue_STR() {
		if(!TextUtils.isEmpty(value_name))return value_name;
		if(TextUtils.isEmpty(value) && !TextUtils.isEmpty(value_default)){
			value = value_default;
		}
		if(choose_items != null && choose_items.size() > 0 && !TextUtils.isEmpty(value)){
			if(TextUtils.isEmpty(value)){

			}else {
				if(!TextUtils.isEmpty(getValueNameFromChooseList(value))){
					return  getValueNameFromChooseList(value);
				}
			}
		}
		return value;
	}

	@JSONField(serialize =  false)
	public void setValue_name(String value_name) {
		this.value_name = value_name;
	}
	public String getValue_name() {
		return value_name;
	}

	public String getHint() {
		return hint;
	}

	public void setHint(String hint) {
		this.hint = hint;
	}

	public String getName_des() {
		return name_des;
	}

	public void setName_des(String name_des) {
		this.name_des = name_des;
	}


	public int getInputtype() {
		return inputtype;
	}

	public void setInputtype(int inputtype) {
		this.inputtype = inputtype;
	}

	public  int getInputType_REAL(){
	    switch (inputtype){
            case INPUT_TYPE_DEFAULT:
                return InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE;
            case INPUT_TYPE_NUM:
                return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_NORMAL;
            case INPUT_TYPE_FLOAT:
				return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
			case INPUT_TYPE_SIGNED:
				return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
        }
		return InputType.TYPE_CLASS_TEXT;
    }

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public ArrayList<ParamsChooseItemData> getChoose_items() {
		return choose_items;
	}

	public void setChoose_items(ArrayList<ParamsChooseItemData> choose_items) {
		this.choose_items = choose_items;
	}

	@JSONField(serialize = false)
	public long getTime_LONG(){
		if(TextUtils.isEmpty(value))return 0;
		if(value.lastIndexOf(",") == -1)return 0;
		String timestr = value.substring(0,value.lastIndexOf(","));
		int indexdot = value.indexOf("\"");
		if(indexdot <0){
			return TimeUtils.getLongTimeByFormat(timestr,"yyyy/MM/dd,HH:mm:ss");
		}else {
			return TimeUtils.getLongTimeByFormat(timestr,TIME_FORMAT);
		}

	}

	@JSONField(serialize = false)
	public String getTIME_STR(){
		if(TextUtils.isEmpty(value))return "";
		long value_long = 0;

		try {
			value_long = Long.valueOf(value);
		}catch (Exception e){
			LogUtil.e("时间格式错误了");
		}

		if(value_long == 0)return "";
		return  TimeUtils.getTimeLongToStrByFormat(value_long,getTimeFormat());
	}

	@JSONField(serialize = false)
	public void setTime_LONG(long time){
		setValue(TimeUtils.getTimeLongToStrByFormat(time,TIME_FORMAT));
	}


	@JSONField(serialize = false)
	public  ArrayList<String> getChooseListString(){
		ArrayList<String> listString = new ArrayList<>();
		for(ParamsChooseItemData data:choose_items){
			listString.add(data.getValue_name());
		}
		return  listString;
	}
	@JSONField(serialize = false)
	public  String getValueNameFromChooseList(String value){
		for(ParamsChooseItemData data:choose_items){
			if(TextUtils.isEmpty(data.getValue()) && TextUtils.isEmpty(value)){
				  	return data.getValue_name();
			}
			if(!TextUtils.isEmpty(data.getValue()) && data.getValue().equals(value)){
				return data.getValue_name();
			}
		}
		return  "";
	}

	public String getWrong_hint() {
		return wrong_hint;
	}

	public void setWrong_hint(String wrong_hint) {
		this.wrong_hint = wrong_hint;
	}

	public int getMax_value() {
		return max_value;
	}

	public void setMax_value(int max_value) {
		this.max_value = max_value;
	}

	public int getMin_value() {
		return min_value;
	}

	public void setMin_value(int min_value) {
		this.min_value = min_value;
	}


	public boolean isVisiable() {
		return isVisiable;
	}
	public void setVisiable(boolean visiable) {
		isVisiable = visiable;
	}

	public String getRelate_name() {
		return relate_name;
	}

	public void setRelate_name(String relate_name) {
		this.relate_name = relate_name;
	}

	public String getRelate_name_value() {
		return relate_name_value;
	}

	public void setRelate_name_value(String relate_name_value) {
		this.relate_name_value = relate_name_value;
	}

	public String getValue_default() {
		return value_default;
	}

	public void setValue_default(String value_default) {
		this.value_default = value_default;
	}

	public int getGroup_position() {
		return group_position;
	}

	public void setGroup_position(int group_position) {
		this.group_position = group_position;
	}

	public boolean[] getListTimeBoolean() {
		if(listTimeBoolean == null){
			return new boolean[]{true, true, true, true, true, true};
		}
		return listTimeBoolean;
	}

	public void setListTimeBoolean(boolean[] listTimeBoolean) {
		this.listTimeBoolean = listTimeBoolean;
	}

	public String getTimeFormat() {
		if(TextUtils.isEmpty(timeFormat)){
			return "yyyy-MM-dd HH:mm:ss";
		}
		return timeFormat;
	}

	public void setTimeFormat(String timeFormat) {
		this.timeFormat = timeFormat;
	}

	public int getMax_length() {
		return max_length;
	}

	public void setMax_length(int max_length) {
		this.max_length = max_length;
	}

	public ArrayList<String> getUrlList() {
		return urlList;
	}

	public void setUrlList(ArrayList<String> urlList) {
		this.urlList = urlList;
	}

	public boolean isAllowEmpty() {
		return isAllowEmpty;
	}

	public void setAllowEmpty(boolean allowEmpty) {
		isAllowEmpty = allowEmpty;
	}

	public int getText_color() {
		return text_color;
	}

	public void setText_color(int text_color) {
		this.text_color = text_color;
	}
}
